﻿using System.Data;

namespace Tszy.Unlimited.Data.AdoNet.Sql.Providers
{
    /// <summary>
    ///
    /// </summary>
    public interface IDataProvider
    {
        /// <summary>
        ///
        /// </summary>
        DatabaseType DatabaseType { get; }

        /// <summary>
        /// 获得数据库连接。
        /// </summary>
        /// <returns>数据库连接。</returns>
        IDbConnection GetConnection();

        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        int Execute(string sql, object parameters = null, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        Task<int> ExecuteAsync(string sql, object parameters, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        object Field(string sql, object parameters = null, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        Task<object> FieldAsync(string sql, object parameters, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        TSource Field<TSource>(string sql, object parameters = null, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        Task<TSource> FieldAsync<TSource>(string sql, object parameters, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="dbTransaction"></param>
        /// <returns></returns>
        IEnumerable<TSource> Query<TSource>(string sql, object parameters = null, IDbTransaction dbTransaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        Task<IEnumerable<TSource>> QueryAsync<TSource>(string sql, object parameters, IDbTransaction transaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="dbTransaction"></param>
        /// <returns></returns>
        IEnumerable<object> Query(Type type, string sql, object parameters = null, IDbTransaction dbTransaction = null);

        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        Task<IEnumerable<object>> QueryAsync(Type type, string sql, object parameters, IDbTransaction transaction = null);
    }
}